# 导包
from api.login import LoginAPI
import config
from common.assertutil import common_assert

# 创建测试接口类
class TestLoginAPI:
    # 设置属性
    uuid = None

    # 前置处理
    def setup(self):
        # 实例化接口对象
        self.login_api = LoginAPI()
        # 获取图片验证码
        res_v = self.login_api.get_verify_code()
        # 获取响应数据中的uuid值
        TestLoginAPI.uuid = res_v.json().get("uuid")

    # 后置处理
    def teardown(self):
        pass

    # 登录成功
    def test01_login_success(self):
        # 登录
        login_data = {
            "username": "admin",
            "password": "admin123",
            "code": "2",
            "uuid": TestLoginAPI.uuid
        }
        res_l = self.login_api.login(login_data)
        # assert 200 == res_l.status_code
        # assert "成功" in res_l.text
        # assert 200 == res_l.json().get("code")
        common_assert(res_l)



    # 登录失败（账号为空）
    def test02_without_username(self):
        # 登录
        login_data = {
            "username": "",
            "password": "admin123",
            "code": "2",
            "uuid": TestLoginAPI.uuid
        }
        res_l = self.login_api.login(login_data)
        # assert 200 == res_l.status_code
        # assert "错误" in res_l.text
        # assert 500 == res_l.json().get("code")
        common_assert(res_l, 200, "错误", 500)

    # 登录失败（账号未注册）
    # 登录失败（密码为空）
    def test03_without_username(self):
        # 登录
        login_data = {
            "username": "admin",
            "password": "",
            "code": "2",
            "uuid": TestLoginAPI.uuid
        }
        res_l = self.login_api.login(login_data)
        # assert 200 == res_l.status_code
        # assert "错误" in res_l.text
        # assert 500 == res_l.json().get("code")
        common_assert(res_l, 200, "错误", 500)
    # 登录失败（密码与账号不符）
